package com.gin.no_gay_alliance.database.dao;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;

import com.gin.no_gay_alliance.database.entity.IpLocationHistory;

import java.util.List;

/**
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/12/26 11:22
 **/
@Dao
public interface IpLocationHistoryDao {
    /**
     * 插入一条IP属地历史
     *
     * @param ipLocationHistory IP属地历史
     */
    @Insert
    void add(IpLocationHistory ipLocationHistory);

    /**
     * 查询指定用户的IP属地历史
     *
     * @param userId 用户id
     * @return IP属地历史
     */
    @Query("SELECT * FROM IpLocationHistory where userId=:userId")
    List<IpLocationHistory> listByUserId(long userId);

    /**
     * 删除指定时间戳之前的 IP属地历史
     *
     * @param timestamp 时间戳
     */
    @Query("delete from IpLocationHistory where timestamp<:timestamp")
    void removeBefore(long timestamp);
}
